<?php
namespace Home\Common;
use Org\Util\Mysql;

class Interview extends Mysql{
	
	//获取待面试条目（按时间正叙）
	function getWait($page){
		$page_item = C("page_item");
		$page = ($page-1)*($page_item);

		$result = $this->mysql->prepare("select * from iry_interview where status = 0 order by thedate limit $page,$page_item");
		$result->execute();
		
		$arResult = array();
		while($row = $result->fetch(\PDO::FETCH_ASSOC)){
			array_push($arResult, array($row['id'], $row['name'], $row['sex'], $row['contact'], $row['job'], 
										$row['itwer'], $row['thedate'], $row['resume'], $row['result']));
		}
		
		return $arResult;
	}
	//获取已面试条目（按时间倒叙）
	function getHave($page){
		$page_item = C("page_item");
		$page = ($page-1)*$page_item;
		$result = $this->mysql->prepare("select * from iry_interview where status = 1 order by id desc limit $page,$page_item");
		$result->execute();
		
		$arResult = array();
		while($row = $result->fetch(\PDO::FETCH_ASSOC)){
			array_push($arResult, array($row['id'],$row['name'], $row['sex'], $row['contact'], $row['job'],
			$row['itwer'], $row['thedate'], $row['resume'], $row['result'],$row['other']));
		}
		
		return $arResult;
	}
	//添加新面试条目
	function addItem($name,$sex,$contact,$job,$itwer,$thedate,$resume){
		$insert = $this->mysql->prepare("insert into iry_interview(name,sex,contact,job,itwer,thedate,resume,result,status) 
				values (\"$name\",$sex,\"$contact\",\"$job\",\"$itwer\",\"$thedate\",\"$resume\",\"待面试\",0)");
		$status = $insert->execute();
		
		if($status) return true;
		else return false;
	}
	
	//搜索条目
	function selectItw($keywork){
		$result = $this->mysql->prepare("select * from iry_interview where name = \"$keywork\" or itwer = \"$keywork\"");
		$result->execute();
		
		$arResult = array();
		while($row = $result->fetch(\PDO::FETCH_ASSOC)){
			array_push($arResult, array($row['id'],$row['name'], $row['sex'], $row['contact'], $row['job'],
			$row['itwer'], $row['thedate'], $row['resume'], $row['result']));
		}
		
		return $arResult;
	}
	//处理面试结果
	function dealItw($id,$result,$other = ""){
		$update = $this->mysql->prepare("update iry_interview set result = \"$result\",other = \"$other\", status = 1 where id = $id");
		$status = $update->execute();
		
		if($status) return true;
		else 		return false;
	}
	//获取单面试条目
	function getOneItw($id){
		$select = $this->mysql->prepare("select * from iry_interview where id = $id");
		$select->execute();
		
		$row = $select->fetch(\PDO::FETCH_ASSOC);
		
		return $row;
	}
}